SELECT items.id, items.title,items.title_eng, items.state, items.hideprice, items.anons, items.price2rub AS price, images.path , 0 + IF(items.title LIKE "%древесин%", 40, 0) + IF(items.anons LIKE "%древесин%", 5, 0) + IF(items.keywords LIKE "%древесин%", 20, 0) + IF(items.comment LIKE "%древесин%", 1, 0) + IF(items.title LIKE "%орех%", 40, 0) + IF(items.anons LIKE "%орех%", 5, 0) + IF(items.keywords LIKE "%орех%", 20, 0) + IF(items.comment LIKE "%орех%", 1, 0) as relevance FROM `items` INNER JOIN `images` ON images.id_item=items.id WHERE ((false OR (items.title LIKE "%древесин%" OR items.anons LIKE "%древесин%" OR items.keywords LIKE "%древесин%" OR items.comment LIKE "% древесин %") OR (items.title LIKE "%орех%" OR items.anons LIKE "%орех%" OR items.keywords LIKE "%орех%" OR items.comment LIKE "% орех %")) ) AND images.visible=0 AND items.visible=1 AND items.price1_ck=0 AND items.state IN (1,2,3,4,7,9) GROUP BY items.id ORDER BY items.price2rub LIMIT 0,32